import React from 'react'
import { createBrowserRouter } from 'react-router-dom'
import MainLayout from '../layouts/MainLayout'
import ManageLayout from '../layouts/ManageLayout'
import QuestionLayout from '../layouts/QuestionLayout'
import Home from '../pages/Home/Home'
import Login from '../pages/Login/Login'
import Registry from '../pages/Registry/Registry'
import Page404 from '../pages/Page404/Page404'
import QuestionList from '../pages/Manage/QuestionList/QuestionList'
import Trash from '../pages/Manage/Trash/Trash'
import Star from '../pages/Manage/Star/Star'
import Stat from '../pages/Question/Stat/Stat'
import Edit from '../pages/Question/Edit/Edit'
const router = createBrowserRouter([
  {
    path: 'question',
    element: <QuestionLayout />,
    children: [
      {
        path: 'stat/:id',
        element: <Stat />,
      },
      {
        path: 'edit/:id',
        element: <Edit />,
      },
    ],
  },
  {
    path: '/',
    element: <MainLayout />,
    children: [
      {
        path: '/',
        element: <Home />,
      },
      {
        path: '/login',
        element: <Login />,
      },
      {
        path: '/Registry',
        element: <Registry />,
      },
      {
        path: 'manage',
        element: <ManageLayout />,
        children: [
          {
            path: 'list',
            element: <QuestionList />,
          },
          {
            path: 'Trash',
            element: <Trash />,
          },
          {
            path: 'Star',
            element: <Star />,
          },
        ],
      },

      {
        path: '*',
        element: <Page404 />,
      },
    ],
  },
])
export default router
// 常用的路由，常量
export const HOME_PATHNAME = '/'
export const LOGIN_PATHNAME = '/login'
export const REGISTER_PATHNAME = '/Registry'
export const MANAGE_INDEX_PATHNAME = '/manage/list'

export function isLoginOrRegistry(pathname: string) {
  if ([LOGIN_PATHNAME, REGISTER_PATHNAME].includes(pathname)) return true
  return false
}

export function isNoNeedLogin(pathname: string) {
  if ([LOGIN_PATHNAME, REGISTER_PATHNAME, HOME_PATHNAME].includes(pathname)) return true
  return false
}
